package com.psa.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.psa.system.R;

import java.util.ArrayList;

/**
 * Created by david on 2014/4/14.
 */
public class ScanInvResultAdapter extends BaseAdapter {
    private Context _context=null;
    private LayoutInflater _inflater = null;
    private ArrayList<String> _data = null;

    public ScanInvResultAdapter(Context context, ArrayList<String> data){
        _context = context;
        _inflater = LayoutInflater.from(_context);
        _data = data;
    }
    @Override
    public int getCount() {
        return _data==null?0:_data.size();
    }

    @Override
    public Object getItem(int i) {
        return _data==null || i<0 || i>=_data.size()?null:_data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        HelperClass helperClass = null;
        if (view == null){
            view = _inflater.inflate(R.layout.scaninv_result_item_view, null);
            helperClass = new HelperClass();
            helperClass.ItemText = (TextView)view.findViewById(R.id.ItemText);
            view.setTag(helperClass);
        } else {
            helperClass = (HelperClass)view.getTag();
        }
        helperClass.ItemText.setText(_data.get(i));
        return view;
    }

    class HelperClass{
        public TextView ItemText;
    }
}
